package com.wolves.career.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wolves.career.entity.ProProfessional;
import com.wolves.career.entity.ProSchool;
import com.wolves.career.service.ProProfessionalService;
import com.wolves.career.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 专业类 前端控制器
 * </p>
 *
 * @author 麦翔盛
 * @since 2021-10-31
 */
@RestController
@RequestMapping("/career/professional")
@CrossOrigin
public class ProProfessionalController {

    @Autowired
    private ProProfessionalService proService;

    @DeleteMapping("/{id}")
    public R removeProfessional(@PathVariable String id){
        proService.removeById(id);
        return R.ok();
    }

    @PutMapping("/pro")
    public R addProfessional(@RequestBody ProProfessional professional){
        proService.save(professional);
        return R.ok();
    }

    @PostMapping("/pro")
    public R updateProfessional(@RequestBody ProProfessional professional){
        proService.updateById(professional);
        return R.ok();
    }

    @PostMapping("/list/{pageNo}/{limit}/{proName}")
    public R listProfessional(@PathVariable long pageNo,
                              @PathVariable long limit,
                              @PathVariable String proName){
        QueryWrapper<ProProfessional> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("profession_name",proName);
        Page<ProProfessional> page = new Page<>(pageNo,limit);
        IPage<ProProfessional> proPage = proService.page(page, queryWrapper);
        return R.ok().data("records",proPage.getRecords()).data("total",proPage.getTotal());

    }

    /**
     * 根据门类id获取专业类
     * @param categoryId
     * @return
     */
    @GetMapping("/getProfessionByCategory/{categoryId}")
    public R getProfessionByCategory(@PathVariable String categoryId){
        List<ProProfessional> list = proService.getProfessionByCategoryId(categoryId);
        return R.ok().data("list",list);

    }
}

